<?php
/**
 * Created by PhpStorm.
 * User: coolinmind
 * Date: 21/01/2019
 * Time: 16:22
 */

namespace App\Services\UCenter;


use App\Services\UCenter\UCenter\CompanyLogic;

class Company
{
    public function companyAuthentication($data)
    {
        $data = pick_array($data, ['user_id', 'name', 'identity_card', 'trading_certificate']);
        ValidateCompany::checkValidate($data, ['user_id', 'name', 'identity_card', 'trading_certificate']);
        return (new CompanyLogic())->companyAuthentication($data);
    }

    //发送邀约
    public function sendInvite($data){
        $data = pick_array($data,['company_id','driver_id']);
        return (new CompanyLogic())->sendInvite($data);
    }

    //邀约列表
    public function inviteList($data){
        $data = pick_array($data,['status','company_id','driver_id']);
        return (new CompanyLogic())->inviteList($data);
    }

    /**
     * 添加车辆
     * @param $data
     * @return array
     * @throws \App\Exceptions\RequestFailException
     */
    public function addCars($data)
    {
        $data = pick_array($data, [
            'plate_type',
            'number',
            'driving_license',
            'car_type',
            'car_length',
            'weight',
            'carriage_num',
            'volume',
            'carrage_length',
            'register_date',
            'car_brand',
            'identification_code',
            'engine',
            'engine_num',
            'car_axle',
            'axle',
            'owner',
            'is_allow',
            'user_id'
        ]);
        ValidateCar::checkValidate($data, [
            'plate_type',
            'number',
            'driving_license',
            'car_type',
            'car_length',
            'weight',
            'carriage_num',
            'volume',
            'carrage_length',
            'register_date',
            'car_brand',
            'identification_code',
            'engine',
            'engine_num',
            'axle',
            'car_axle',
            'owner',
            'is_allow',
            'user_id'
        ]);
        return (new CompanyLogic())->addCars($data);
    }

    //司机与车辆进行绑定
    public function driverAndCar($data){
        $data = pick_array($data,['car_id','driver_id','company_id']);
        return (new CompanyLogic())->driverAndCar($data);
    }

    //移除司机与车辆进行绑定
    public function removeDriverAndCar($data){
        $data = pick_array($data,['id']);
        ValidateCompany::checkValidate($data, ['id']);
        return (new CompanyLogic())->removeDriverAndCar($data);
    }

    //通过姓名或手机号查找公司下的员工
    public function companyDriverByRea($data){
        $data = pick_array($data,['name','phone','company_id']);
        ValidateCompany::checkValidate($data, ['name', 'phone']);
        return (new CompanyLogic())->companyDriverByRea($data);
    }

    //同意邀约
    public function agreeInvite($data){
        $data = pick_array($data,['id']);
        ValidateCompany::checkValidate($data, ['id']);
        return (new CompanyLogic())->agreeInvite($data);
    }

    //查看车辆下的司机
    public function carHasDriver($data){
        $data = pick_array($data,['id']);
        ValidateCompany::checkValidate($data, ['id']);
        return (new CompanyLogic())->carHasDriver($data);
    }

    //车辆移除
    public function removeCompanyCar($data){
        $data = pick_array($data,['id']);
        ValidateCompany::checkValidate($data, ['id']);
        return (new CompanyLogic())->removeCompanyCar($data);
    }

    //车辆审核列表
    public function carCheckList($data){
        return (new CompanyLogic())->carCheckList($data);
    }

    //车辆管理
    public function driverManage($data){
        $data = pick_array($data,['name','phone','card_type','count','company_id']);
        ValidateCompany::checkValidate($data, ['name','phone']);
        return (new CompanyLogic())->driverManage($data);
    }

    //公司司机解绑
    public function companyDriverUnbind($data){
        $data = pick_array($data,['id']);
        ValidateCompany::checkValidate($data, ['id']);
        return (new CompanyLogic())->companyDriverUnbind($data);
    }

    //拒绝邀约
    public function refuseInvite($data){
        $data = pick_array($data,['id']);
        ValidateCompany::checkValidate($data, ['id']);
        return (new CompanyLogic())->refuseInvite($data);
    }

    //运输管理
    public function wayBillManage($data){
        $data = pick_array($data, ['page', 'user_id', 'number', 'car_length', 'weight', 'plate_type','type']);
        ValidateCar::checkValidate($data, ['page', 'user_id']);
        return (new CompanyLogic())->wayBillManage($data);
    }

    //获取配置信息
    public function getSetting($data){
        $data = pick_array($data, ['action']);
        return (new CompanyLogic())->getSetting($data);
    }

    //委托申请数量
    public function entrustCount($data){
        $data = pick_array($data, ['user_id']);
        ValidateCar::checkValidate($data, ['user_id']);
        return (new CompanyLogic())->entrustCount($data);
    }
}
